#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<sys/socket.h>

#define BUF_SIZE 100

int main(void)
{
    struct sockaddr_in server_addr;
    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    server_addr.sin_port = htons(1234);

    char bufSend[BUF_SIZE] = {0};
    char bufRecv[BUF_SIZE] = {0};

    // char buffer[50];
    // read(sock, buffer, sizeof(buffer)-1);
    // printf("Message from server: %s\n", buffer);

    while(1){
        int sock = socket(AF_INET, SOCK_STREAM, 0);
        connect(sock, (struct sockaddr*)&server_addr, sizeof(server_addr));

        // send data
        printf("Please input a string: ");
        scanf("%s", bufSend);
        send(sock, bufSend, strlen(bufSend), 0);

        recv(sock, bufRecv, BUF_SIZE, 0);
        printf("Return message: %s \n", bufRecv);

        memset(bufSend, 0, BUF_SIZE);
        memset(bufRecv, 0, BUF_SIZE);
        close(sock);}

    return 0;
}